package com.example.deploysinggle.test1.common.aop;

import com.example.deploysinggle.test1.common.util.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2024/11/18 9:59
 */
@Aspect
@Component
@Slf4j
public class InvokeMethodAop {
    @Around("@annotation(com.example.deploysinggle.test1.common.annotation.SysLog)")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        long start = System.currentTimeMillis();

        try {
            log.info("requesst:{} with arguments: {}",point.getSignature(), JsonUtil.toJson(point.getArgs()));
            Object result = point.proceed();
            long end = System.currentTimeMillis();
            log.info("requesst:{} with arguments: {} response:{}.cost:{}ms",point.getSignature(), JsonUtil.toJson(point.getArgs()),JsonUtil.toJson(result),end-start);
            return result;
        } catch (Throwable throwable) {
            long end = System.currentTimeMillis();
            throwable.printStackTrace();
            //区分公共异常 以及其他异常 并作处理
            return null;
        }
    }
    }

